import { reqOrder, reqUserAdress } from "@/api"
export default {
  namespaced: true,
  state: {
    userAddressList: [],
    tradeInfo: {}
  },
  mutations: {
    // 1.设置用户住址
    SetUserAdress(state, userAddressList) {
      state.userAddressList = userAddressList
    },
    // 2.设置订单详情
    SetTradeOrder(state, tradeInfo) {
      state.tradeInfo = tradeInfo
    }
  },
  actions: {
    // 1.获取用户住址的数据
    async getUserAdress({ commit }) {
      let res = await reqUserAdress()
      if (res.code === 200) {
        commit("SetUserAdress", res.data)
      } else {
        console.log(res.message)
      }
    },
    // 2.获取订单详情数据
    async getTradeOrder({ commit }) {
      let res = await reqOrder()
      if (res.code === 200) {
        commit("SetTradeOrder", res.data)
      } else {
        console.log(res.message)
      }
    }
  },
  getters: {
    // 1.商品列表
    detailArrayList(state){
      return state.tradeInfo.detailArrayList
    },
    // 2.商品总金额
    originalTotalAmount(state){
      return state.tradeInfo.originalTotalAmount
    },
    // 3.实付金额
    totalAmount(state){
      return state.tradeInfo.totalAmount
    },
    // 4.商品数量
    totalNum(state){
      return state.tradeInfo.totalNum
    },
    // 5.订单编号
    tradeNo(state){
      return state.tradeInfo.tradeNo
    }
  }
}